package com.terry.test3;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

/**
 * 计算堆栈中的剩余数字
 * 输入  5 10 20 50 85 1
 * 输出  1 170
 * @author 小八
 * @date 2023年02月13日15:44
 */
public class Title33 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String[] split = in.nextLine().split(" ");
            int [] arr = new int[split.length];
            for (int i = 0; i < split.length; i++) {
                arr[i] = Integer.parseInt(split[i]);
            }
            Deque<Integer> deque = new ArrayDeque<>();
            int[] mark = new int[arr.length];
            int markSize = 0;
            for (int i = 0; i < arr.length; i++) {
                if(deque.isEmpty()){
                    deque.addLast(arr[i]);
                    mark[markSize++] = arr[i];
                }else{
                    int index = indexOf(mark,arr[i],markSize);
                    int value = arr[i];
                    if(index != -1){
                        do {
                            while (deque.size() != index) {
                                deque.removeLast();
                            }
                            markSize = index;
                            for (int j = markSize - 1; j >= 0; j--) {
                                mark[j] = mark[j] -= value;
                            }
                            value = 2*value;
                            index = indexOf(mark,value,markSize);
                        }while (index!=-1);
                        mark[markSize++]  = value;
                        deque.addLast(value);
                    }else{
                        deque.addLast(value);
                        for(int j= markSize-1;j>=0;j--){
                            mark[j] = mark[j] += value;
                        }
                        mark[markSize++]  = value;
                    }
                }
            }
            while(!deque.isEmpty()){
                System.out.print(deque.removeLast()+" ");
            }
        }
    }


    public static int indexOf(int[] mark,int value,int markSize){
        for (int i = 0; i < markSize; i++) {
            if(mark[i] == value){
                return i;
            }
        }
        return -1;
    }
}
